<?php

namespace app\common\model\xiluhouse;

use think\Model;
use app\common\model\User;

class RentalRequest extends Model
{
    // 表名
    protected $name = 'rental_request';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    
    // 追加属性
    protected $append = [
        'room_type_text',
        'gender_text',
        'status_text',
        'is_delete_text',
        'apply_status_text'
    ];

    // 定义默认值
    protected $insert = [
        'status' => 'normal',
        'is_delete' => 2,
        'apply_status' => 2
    ];

    /**
     * 关联用户表
     */
    public function user()
    {
        return $this->hasOne('app\common\model\User', 'id', 'user_id');
    }
    
    /**
     * 户型获取器
     */
    public function getRoomTypeTextAttr($value, $data)
    {
        return $data['room_num'].'室'.$data['ting_num'].'厅'.$data['wei_num'].'卫';
    }

    /**
     * 性别获取器
     */
    public function getGenderTextAttr($value, $data)
    {
        $value = isset($data['gender']) ? $data['gender'] : 0;
        $list = [
            0 => '不限',
            1 => '男',
            2 => '女'
        ];
        return isset($list[$value]) ? $list[$value] : '不限';
    }

    /**
     * 状态获取器
     */
    public function getStatusTextAttr($value, $data)
    {
        $value = isset($data['status']) ? $data['status'] : 'normal';
        $list = [
            'normal' => '正常',
            'hidden' => '隐藏'
        ];
        return isset($list[$value]) ? $list[$value] : '';
    }

    /**
     * 删除状态获取器
     */
    public function getIsDeleteTextAttr($value, $data)
    {
        $value = isset($data['is_delete']) ? $data['is_delete'] : 2;
        $list = [
            1 => '已删除',
            2 => '未删除'
        ];
        return isset($list[$value]) ? $list[$value] : '';
    }

    /**
     * 审核状态获取器
     */
    public function getApplyStatusTextAttr($value, $data)
    {
        $value = isset($data['apply_status']) ? $data['apply_status'] : 2;
        $list = [
            1 => '已审核',
            2 => '待审核',
            3 => '已拒绝'
        ];
        return isset($list[$value]) ? $list[$value] : '';
    }
} 